<template>
	<view class="page-content">
		<view class="search-box">
			<custom-input placeholder="搜索" background="#FFFFFF" :text="filterParmas.searchValue"
				@handleSearch="handleSearch"></custom-input>
		</view>

		<scroll-view scroll-y="true" style="flex: 1; overflow: hidden" @scrolltolower="addRandomData"
			:refresher-enabled="true" @refresherrefresh="handlerefresh" :refresher-triggered="showrefresh"
			:show-scrollbar="false">
			<template v-if="dataList.length === 0 && status === 'nomore'">
				<empty></empty>
			</template>
			<template v-else>
				<view class="cards-list">
					<view class="mt-16" v-for="(item, index) in dataList" @click="handleToDetail(item.id)" :key="index">
						<view class="flex-row justify-between">
							<view class="flex-row">
								<view class="flex-col justify-start items-center  relative group_4">
									<u-image height="80rpx" width="80rpx" shape="circle" :src="item.avatar&&item.avatar.split(',')[0]" />
									<!-- <image
						        class="image_5 pos_2"
						        src="https://ide.code.fun/api/image?token=662b6372d578370011c46423&name=39bf13820338234b42da31bfd6c3f21d.png"
						      /> -->
								</view>
								<view class="flex-col items-start  self-center group_5">
									<text class="font">{{item.nickName||'--'}}</text>
									<text class="font_2 text_2 mt-11">{{item.message||'--'}}</text>
								</view>
								<text class="self-start font_3 text_3">{{item.createTime||'--'}}</text>
							</view>
							<image height="80rpx" width="80rpx" border-radius="circle" :src="item.photo&&item.photo.split(',')[0]" />
						</view>
					</view>
					<u-loadmore :status="status" />
				</view>
			</template>
		</scroll-view>
	</view>
</template>

<script>
	import mine from '../../../api/mine';
	import customInput from "components/common/custom-input.vue";
	import empty from "components/common/empty/empty.vue";
	export default {
		data() {
			return {
				status: "loadmore",
				dataList: [], //数据列表
				filterParmas: {
					searchValue: "",
					pageNum: 0,
					pageSize: this.$config.pageSize,
				}, //筛选参数
				showrefresh: false,
			};
		},
		onLoad() {
			this.getDataList()
		},
		methods: {
			addRandomData() {
				if (this.status === "loadmore") this.getDataList();
			},
			getDataList() {
				if (this.status !== "loading") {
					this.status = "loading";
					this.filterParmas.pageNum++;
					mine
						.getRecordingList(this.filterParmas)
						.then((res) => {
							if (res.code === 200) {
								this.dataList.push(...res.rows);
								if (res.rows?.length < this.$config.pageSize)
									this.status = "nomore";
								else {
									this.status = "loadmore";
								}
								this.showrefresh = false;
							} else {
								throw Error();
							}
						})
						.catch((err) => {
							this.status = "nomore";
							this.showrefresh = false;
							console.log(err);
						});
				}
			},
			handleSearch(val) {
				this.filterParmas.searchValue = val;
				this.filterParmas.pageNum = 0;
				this.dataList = [];
				this.getDataList();
			},
			handlerefresh() {
				this.showrefresh = true;
				this.dataList = [];
				this.filterParmas.pageNum = 0;
				this.getDataList();
			},
		},
		components: {
			customInput,
			empty
		}
	}
</script>

<style lang="scss" scoped>
	.page-content {
		height: 100%;
		background-color: #f6f6f6;
		padding: 0 32rpx;
		display: flex;
		flex-direction: column;

		.search-box {
			padding: 16rpx 0 24rpx 0;
		}

		.cards-list {
			position: relative;

			.mt-16 {
				&:first-child {
					margin-top: 0;
				}
			}

			.mt-11 {
				margin-top: 22rpx;
			}

			.group_4 {
				width: 84.66rpx;

				.image_5 {
					width: 26rpx;
					height: 26rpx;
				}

				.pos_2 {
					position: absolute;
					right: 0;
					bottom: 6rpx;
				}
			}

			.group_5 {
				margin-left: 12rpx;

				.font {
					font-size: 28rpx;
					font-family: PingFang SC;
					line-height: 20rpx;
					font-weight: 700;
					color: #000000;
				}

				.font_2 {
					font-size: 24rpx;
					font-family: PingFang SC;
					line-height: 22.56rpx;
					font-weight: 700;
					color: #666666;
				}

				.text_2 {
					line-height: 22.4rpx;
				}
			}

			.font_3 {
				font-size: 24rpx;
				font-family: PingFang SC;
				line-height: 17.48rpx;
				color: #999999;
			}

			.text_3 {
				margin-left: 32rpx;
				margin-top: 56rpx;
			}

		}
	}
</style>